package net.jxvtc.eshop.service;

import java.sql.SQLException;
import java.util.List;

import net.jxvtc.eshop.dao.ProductDao;
import net.jxvtc.eshop.domain.Product;
import net.jxvtc.eshop.domain.ProductPageBean;
import net.jxvtc.eshop.exception.FindProductByIdException;

public class ProductService {
	private ProductDao dao = new ProductDao();
	public Product findProductById(String id) throws FindProductByIdException{
		try {
			return dao.findProductById(id);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new FindProductByIdException("根据ID查找商品失败");
		}
	}
	public ProductPageBean findProductByPage(int currentPage, int currentCount, String category) {
		ProductPageBean bean =null;
	
		try {
			// 获取总条数
			int totalCount = dao.findAllCount(category);
		
			// 获取总页数
		
			// 获取当前页数据
			List<Product> ps = dao.findByPage(currentPage, currentCount,
					category);
		
			bean=new ProductPageBean(totalCount, currentCount, ps);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return bean;
	}

}
